package cn.jietuo.juc.c_007_reentrant;

import java.util.concurrent.Exchanger;

/**
 * @author zhangx & jietuo_zx@163.com
 * @version 1.0
 * @date 2020/5/8
 * @description: Exchanger实践  线程间交换数据
 */
public class T09_Exchanger {

    static Exchanger<String> exchanger = new Exchanger<>();

    public static void main(String[] args) {
        new Thread(() -> {
            String t1 = "T1";
            try {
                t1 = exchanger.exchange(t1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t1:" + t1);
        }).start();

        new Thread(() -> {
            String t2 = "T2";
            try {
                t2 = exchanger.exchange(t2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t2:" + t2);
        }).start();
    }
}
